<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>1-react生命周期</title>
</head>

<body>
  <div id="root"></div>
  <script type="text/javascript" src="../js/react.development.js"></script>
  <script type="text/javascript" src="../js/react-dom.development.js"></script>
  <script type="text/javascript" src="../js/prop-types.js"></script>
  <script type="text/javascript" src="../js/babel.min.js"></script>
  <script type="text/babel">
    class Test extends React.Component {
      state = {
        opacity: 0.5
      }
      componentDidMount() {
        this.timer = setInterval(() => {
          let { opacity } = this.state
          opacity -= 0.1
          if (opacity <= 0) opacity = 1
          this.setState({ opacity })
        }, 200);
      }
      componentWillUnmount() {
        clearInterval(this.timer)
      }
      refuseStudy = () => {
        ReactDOM.unmountComponentAtNode(document.getElementById('root'))
      }
      render() {
        return (
          <div>
            <h1 style={{ opacity: this.state.opacity }}>react真简单，真好用</h1>
            <button onClick={this.refuseStudy}>不学了</button>
          </div>
        )
      }
    }
    ReactDOM.render(<Test />, document.getElementById('root'))
  </script>
</body>

</html>